<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="exportData">导出</a-button>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup name="electronicGoldUse">
import { BasicTable, useTable } from '@apps/antd-admin/src/components/table';
import { electronicGoldPage, exportExcel } from './api';
import { columns, searchFormSchema } from './data';

const [registerTable, { getForm }] = useTable({
  title: '苏南电子金',
  api: electronicGoldPage,
  columns,
  formConfig: {
    labelWidth: 140,
    labelCol: { span: 5 },
    schemas: searchFormSchema,
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  showIndexColumn: true,
});

function exportData() {
  let form = getForm().getFieldsValue();
  exportExcel(form).then((data) => {
    let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }));
    let link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', '电子金记录.xlsx');
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link); //下载完成移除元素
    window.URL.revokeObjectURL(url); //释放掉blob对象
  });
}
</script>
